SpaceToDepth
将输入张量的空间维按 block 重排到深度通道(Space → Depth)。
输入/输出均为 NHWC 格式:[batch, height, width, channel]。
要求输入高、宽 \(H\)、\(W\) 能被 \(B\) 整除,其中 \(B\) 为 block。
设输入形状为 \([N, H, W, C]\),则输出形状为:
\[\begin{split}\begin{aligned}
N_{out} &= N \\
H_{out} &= H / B \\
W_{out} &= W / B \\
C_{out} &= C \cdot B^{2}
\end{aligned}\end{split}\]
元素总数不变。对输出坐标 \((n, h, w)\) 与块内偏移 \((k_h, k_w)\)、通道 \(c\):
\[\begin{split}\begin{aligned}
y_{in} &= h \cdot B + k_h \\
x_{in} &= w \cdot B + k_w \\
c_{out} &= (k_h \cdot B + k_w) \cdot C + c
\end{aligned}\end{split}\]
即 \(O[n, h, w, c_{out}] = I[n, y_{in}, x_{in}, c]\)。
本实现无 mode 参数,通道排列固定为上述形式(与 DepthToSpace 的 DCR 互逆)。
- 输入:
input - 输入数据地址
in_shape - 输入形状,格式为
[batch, height, width, channel]block - 分块因子 \(B\)
core_mask - 核掩码(仅共享存储版本使用)
- 输出:
output - 输出数据地址
- 支持平台:
FT78NEMT7004
备注
FT78NE 支持 int8, int16, int32, fp32, fp64, cplx64, cplx128
MT7004 支持 int16, int32, fp16, fp32, cplx64
共享存储版本:
-
void i8_space_to_depth_s(int8_t *input, int8_t *output, int *in_shape, int block, int core_mask)
-
void i16_space_to_depth_s(int16_t *input, int16_t *output, int *in_shape, int block, int core_mask)
-
void i32_space_to_depth_s(int *input, int *output, int *in_shape, int block, int core_mask)
-
void hp_space_to_depth_s(float16 *input, float16 *output, int *in_shape, int block, int core_mask)
-
void fp_space_to_depth_s(float *input, float *output, int *in_shape, int block, int core_mask)
-
void dp_space_to_depth_s(double *input, double *output, int *in_shape, int block, int core_mask)
-
void c64_space_to_depth_s(float *input, float *output, int *in_shape, int block, int core_mask)
-
void c128_space_to_depth_s(double *input, double *output, int *in_shape, int block, int core_mask)
C调用示例:
1// MT7004 示例(共享存储多核,DDR 地址)
2void TestSpaceToDepthSMCFp32(int core_mask) {
3 int core_id = get_core_id();
4 int logic_core_id = GetLogicCoreId(core_mask, core_id);
5 int core_num = GetCoreNum(core_mask);
6 float *input = (float *)0x81000000;
7 float *output = (float *)0x82000000;
8 int in_shape[4] = {1, 8, 8, 4};
9 int block = 2;
10 sys_bar(0, core_num);
11 fp_space_to_depth_s(input, output, in_shape, block, core_mask);
12}
13
14void main() {
15 int core_mask = 0b1111;
16 TestSpaceToDepthSMCFp32(core_mask);
17}
私有存储版本:
-
void i8_space_to_depth_p(int8_t *input, int8_t *output, int *in_shape, int block)
-
void i16_space_to_depth_p(int16_t *input, int16_t *output, int *in_shape, int block)
-
void i32_space_to_depth_p(int *input, int *output, int *in_shape, int block)
-
void hp_space_to_depth_p(float16 *input, float16 *output, int *in_shape, int block)
-
void fp_space_to_depth_p(float *input, float *output, int *in_shape, int block)
-
void dp_space_to_depth_p(double *input, double *output, int *in_shape, int block)
-
void c64_space_to_depth_p(float *input, float *output, int *in_shape, int block)
-
void c128_space_to_depth_p(double *input, double *output, int *in_shape, int block)
C调用示例:
1// MT7004 示例(私有存储单核,AM 地址)
2void TestSpaceToDepthAMFp32(void) {
3 float *input = (float *)0x10000000;
4 float *output = (float *)0x10010000;
5 int in_shape[4] = {1, 8, 8, 4};
6 int block = 2;
7 fp_space_to_depth_p(input, output, in_shape, block);
8}
9
10void main() {
11 TestSpaceToDepthAMFp32();
12}